import 'package:flutter/material.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/base/empty_controller.dart';
import 'package:get/get.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/provider/base_controller.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/sp_util.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({Key? key}) : super(key: key);

  @override
  SplashPageState createState() {
    return SplashPageState();
  }
}

class SplashPageState extends BaseState<SplashPage, BaseController> {
  @override
  BaseController registerController() => Get.put(EmptyController());

  @override
  void frameCallback(Duration timeStamp) {
    if (SPUtil.token.isNotEmpty) {
      if (Constant.mainIsRun) {
        Get.offAllNamed(Routers.main);
      } else if (Constant.dispatcherIsRun) {
        Get.offAllNamed(Routers.dispatcher);
      }
    } else {
      if (Constant.dispatcherIsRun) {
        Get.offAllNamed(Routers.dispatcher);
      } else {
        Get.offAllNamed(Routers.login);
      }
    }
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return Container();
  }

}
